package monarc.jscheduler.dag;

import edu.uci.ics.jung.graph.impl.DirectedSparseGraph;
import monarc.jscheduler.dag.StatusCatalog;
import monarc.jscheduler.dag.graph.Nod;
import monarc.jscheduler.dag.ReschedulingProcedure;
import monarc.center.Farm;

// nu cred ca e cea mai fericita alegere a numelui

public class SystemMonitor{
	
	Farm ownerFarm;
	DirectedSparseGraph g;
	
	SystemMonitor(DirectedSparseGraph g, Farm owner){
		ownerFarm = owner;
		this.g = g;
	}
	
	 public void chooseAlg(){	 
		 setSchedulingAlg(parametersComputation());
	 }
	
	public void setSchedulingAlg(String algorithm){
		((DAGScheduler)ownerFarm.jobScheduler).setAlgoritmToUse(algorithm);
	}
	
	public String selectSchedulingAlg(String i){
		/*if(i[0]=='a'){
			if(i[1]=='a'){}
			else{
				if(i[1]=='b'){}
				else{
					if(i[1]=='c'){}
				}
			}
		}
		else{
			if(i[0]=='b'){
				if(i[1]=='a'){}
				else{
					if(i[1]=='b'){}
					else{
						if(i[1]=='c'){}
					}
				}
			}
			else{
				if(i[0]=='c'){
					if(i[1]=='a'){}
					else{
						if(i[1]=='b'){}
						else{
							if(i[1]=='c'){}
						}
					}
				}
			}
		}*/
			
		return new String();
	}

	private int parametersComputation4(SystemStatus analysis){
		int p0=1;
		if(analysis.same_cluster == true){
			
			return p0*10+1;
		}
		else{
			
			return p0*10;
		}
	}
	
	private int parametersComputation3(SystemStatus analysis){
		int p1;
		if(analysis.homogeneous == true){
			p1 = parametersComputation4(analysis);
			return p1*10+1;
		}
		else{
			p1 = parametersComputation4(analysis);
			return p1*10;
		}	
	}
	
	private String parametersComputation2(SystemStatus analysis){
		int p2;
		if(analysis.heterogeneous_type == 1){
			p2 = parametersComputation3(analysis);
			return "a"+p2;
		}
		else
		{
			if(analysis.heterogeneous_type == 2){
				p2 = parametersComputation3(analysis);
				return "b"+p2;
			}
			else
				if(analysis.heterogeneous_type == 3){
					p2 = parametersComputation3(analysis);
					return "c"+p2;
				}
		}
		return new String();
	}
	
	private String parametersComputation1(int p2, SystemStatus analysis){
		String p3;
		if(p2 == SystemStatus.ResCPUbound){
			p3 = parametersComputation2(analysis);
			return "a"+p3;
		}
		else{	
			if(p2 == SystemStatus.ResCPUmixedIO){
				p3 = parametersComputation2(analysis);
				return "b"+p3;
			}
			else
				if(p2 == SystemStatus.ResIObound){
					p3 = parametersComputation2(analysis);
					return "c"+p3;
				}
		}
		return new String();	
	}
	
	public String parametersComputation(){
		SystemStatus analysis = new SystemStatus(ownerFarm);
		int p1 = analysis.calcCCR(g);
		int p2 = analysis.detResourcesType(ownerFarm);
		analysis.detResourcesOmogenity(ownerFarm);
		String p3;
		
		if(p1 == SystemStatus.CPUbound){
			p3 = parametersComputation1(p2, analysis);
			return "a"+p3;
		}else{
			if(p1 == SystemStatus.CPUmixedIO){
				p3 = parametersComputation1(p2, analysis);
				return "b"+p3;
			}
			else
				if(p1 == SystemStatus.IObound){
					p3 = parametersComputation1(p2, analysis);
					return "c"+p3;
				}
			return new String();
		}
	}	
}
	
	